/**
 * @Auther: wangliuyang
 * @Date: 2021/4/18 16:49
 * @Description: 删除链表的倒数第 N 个结点
 */
public  class Solution_19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode headNode = new ListNode(0, head);
        ListNode start = headNode;
        ListNode end = headNode;
        while(n != 0) {
            end = end.next;
            n--;
        }
        while (end.next != null) {
            end = end.next;
            start = start.next;
        }
        start.next = start.next.next;
        return headNode.next;
    }
}
class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}